package main

import (
	"io"
	"log"
	"net/http"
	"os"
)

func main() {
	// 注册handle
	http.HandleFunc("/", rootHandler)
	http.HandleFunc("/healthz", healthzHandler)
	// 绑定和监听80端口
	err := http.ListenAndServe(":80", nil)
	if err != nil {
		log.Fatal(err)
	}
}

func healthzHandler(w http.ResponseWriter, r *http.Request) {
	log.Println("/healthz ClientAddress is " + r.RemoteAddr + " Status Code is " + http.StatusText(200))
	io.WriteString(w, http.StatusText(200))
}

func rootHandler(w http.ResponseWriter, r *http.Request) {
	for k, v := range r.Header {
		for _, value := range v {
			w.Header().Set(k, value)
		}
	}
	os.Setenv("VERSION", "1.18.4")
	version := os.Getenv("VERSION")
	w.Header().Set("version", version)

	log.Println("/ ClientAddress is " + r.RemoteAddr + " Status Code is " + http.StatusText(200))
}
